﻿using System.Linq;
using CardPlay.Model.CardModel;
using CardPlay.Model.GameModel;
using CardPlay.Model.GameModel.Presentation;
using CardPlay.Model.Layout;

namespace CardPlay.DemoPack.Games.FreeCellVariants
{
    [Game("A9A5C8B5-BBDF-436C-947C-3CC4BEE2C482", LevelOfDifficulty.Medium, LevelOfSkill.MostlySkill, DurationOfPlay.Within5To10Minutes, Family = FamilyName)]
    public class SeaTowers : FreeCellBase
    {
        public SeaTowers()
        {
            TotalTableaus = 10;
            TotalReserves = 4;
        }

        public override ILayoutSite CreatePresentation(IPresentationContext presentation)
        {
            var metrics = presentation.Metrics;

            var root = new SideBySideLayout
                       {
                           HorizontalContentAlignment = HorizontalAlignment.Stretch,
                           VerticalContentAlignment = VerticalAlignment.Top,
                           Direction = SpreadDirection.Vertical,
                           MinimumSpacing = metrics.MinSpacingDown,
                           MaximumSpacing = metrics.MinSpacingDown
                       };

            {
                var topRow = presentation.CreateRowLayout(); // CreateSideBySideLayout(metrics);
                topRow.HorizontalContentAlignment = HorizontalAlignment.Center;

                foreach (var name in PilesNamed("foundation.[1-2]").Select(pile => pile.Name))
                    topRow.Add(presentation.CreatePileVisual(name, StandardStyles.Foundation));

                topRow.Add(presentation.CreateCardSpacer());

                var style = new VisualTraits
                            {
                                EmptyCue = () => EmptyPileCue.CardSite,
                                Arrangement = CardArrangement.StackSquare,
                                ContentFit = ContentFit.FitHeight
                            };

                foreach (var pile in PilesNamed(AnyReserve))
                    topRow.Add(presentation.CreatePileVisual(pile.Name, style));

                topRow.Add(presentation.CreateCardSpacer());

                foreach (var name in PilesNamed("foundation.[3-4]").Select(pile => pile.Name))
                    topRow.Add(presentation.CreatePileVisual(name, StandardStyles.Foundation));

                root.Add(topRow);
            }

            {
                var tableau = presentation.CreateRowLayout(); // CreateSideBySideLayout(metrics);
                //tableau.VerticalContentAlignment = VerticalAlignment.Top;

                foreach (var pile in PilesNamed(AnyTableau))
                    tableau.Add(presentation.CreatePileVisual(pile.Name, StandardStyles.Tableau));

                root.Add(tableau);
            }

            return root;
        }

        protected override void PrepareDealScript(DealScript script)
        {
            script.Deal("1 up").To("reserve.2");
            script.Deal("1 up").To("reserve.3");
            script.DealToEach(NamesOfTableaus, "5 up");
        }
    }
}